package sanshi.contect.udpstarter.util;

import java.util.regex.Pattern;

/**
 * 对ip格式进行验证
 */
public class UDPHostUtil {

    /**
     * ip 格式进行验证
     * @param ipAddress ip地址或者localhost
     * @return 验证结果
     */
    public static boolean isValidIPAddress(String ipAddress) {
        if ((ipAddress != null) && (!ipAddress.isEmpty())) {
            if ("localhost".equals(ipAddress)){
                return true;
            }else {
                return Pattern.matches("^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$", ipAddress);
            }
        }
        return false;
    }
}
